package io.gitee.yanbinchen;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @author: alex
 * @since : 2025-02-28 23:17
 */
public class CacheContextHolder {
    private static ConcurrentHashMap<String, SuperKey> META_INFO_MAP = new ConcurrentHashMap<>(64);
    private static ConcurrentHashMap<String, DelSuperKey> DEL_META_INFO_MAP = new ConcurrentHashMap<>(64);

    private static SuperCacheService superCacheService;

    public static SuperKey get(String name) {
        return META_INFO_MAP.get(name);
    }

    public static DelSuperKey getDel(String name) {
        return DEL_META_INFO_MAP.get(name);
    }

    public static void put(String metaId, SuperKey superKey) {
        if (META_INFO_MAP.contains(metaId)) {
            throw new SuperCacheException(-1, "MetaId must not be duplicate 【" + metaId + "】");
        }
        META_INFO_MAP.put(metaId, superKey);
    }

    public static void putDel(String metaId, DelSuperKey delSuperKey) {
        if (DEL_META_INFO_MAP.contains(metaId)) {
            throw new SuperCacheException(-1, "MetaId must not be duplicate 【" + metaId + "】");
        }
        DEL_META_INFO_MAP.put(metaId, delSuperKey);
    }

    public static SuperCacheService getSuperCacheService() {
        return superCacheService;
    }

    public static void setSuperCacheService(SuperCacheService superCacheService) {
        CacheContextHolder.superCacheService = superCacheService;
    }
}
